import { Body, Get, Post, Delete, Put, Param, Query } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';

export class BasicController<T = any> {
  constructor(private readonly _service) {}

  @ApiOperation({ summary: '创建' })
  @Post('create')
  async create(@Body() data: T) {
    return await this._service.create(data);
  }

  @ApiOperation({ summary: '删除' })
  @Delete('delete/:id')
  async delete(@Param('id') id: number) {
    return await this._service.delete(id);
  }

  @ApiOperation({ summary: '更新' })
  @Put('update/:id')
  async update(@Param('id') id: number, @Body() data: T) {
    return await this._service.update(id, data);
  }

  @ApiOperation({ summary: '获取列表' })
  @Get('list')
  async list(): Promise<T[]> {
    return await this._service.list();
  }

  @ApiOperation({ summary: '根据id查询单条数据' })
  @Get('info')
  async info(@Query('id') id: number): Promise<T> {
    return await this._service.info(id);
  }
}
